import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
import panel.CreateDialogPanel;
import util.CloseListener;

import javax.swing.*;
import java.awt.*;

/**
 * 创建Dialog
 */
public class CreateDialogAction extends AnAction {

    private JDialog jFrame;
    private CreateDialogPanel createDialogPanel;

    @Override
    public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
        createDialogPanel = new CreateDialogPanel(anActionEvent, new CloseListener() {
            @Override
            public void onClose() {
                jFrame.dispose();
            }
        });
        initSelectView();
    }

    private void initSelectView() {
        jFrame = new JDialog();
        jFrame.setTitle("生成自定义Dialog");
        jFrame.setResizable(false);
        jFrame.setModal(true);
        Container container = jFrame.getContentPane();
        container.add(createDialogPanel);
        jFrame.setSize(400, 200);
        jFrame.setLocationRelativeTo(null);
        jFrame.setVisible(true);
    }
}
